package yue.shen.android.demo.net

import android.app.Application
import android.content.Context
import android.net.ConnectivityManager
import android.net.NetworkRequest

object NetworkManager {

    /**
     * 初始化网络监听
     */
    fun init(application: Application){
        val networkCallback = NetworkCallbackImpl()
        val builder = NetworkRequest.Builder()
        val request = builder.build()
        val manager = application.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
        manager.registerNetworkCallback(request,networkCallback)
    }

}